package service.impl;

import mapper.IBusinessMapper;
import org.apache.ibatis.session.SqlSession;
import pojo.Business;

import service.IBusinessService;
import utils.MybatisUtils;
import vo.ResponseVo;

import java.util.List;

public class BusinessService implements IBusinessService {
    //1.获取Mapper

    @Override
    public ResponseVo<List<Business>> getBusinessList() {

        SqlSession sqlSession = MybatisUtils.getSqlSession();
        IBusinessMapper mapper =sqlSession.getMapper(IBusinessMapper.class);
        List<Business> list=mapper.getBusinessList();
        //2.调用mapper层相应方法
        ResponseVo<List<Business>> responseVo=new ResponseVo<>();

        responseVo.setFlag(true);
        responseVo.setMessage("查询成功");
        responseVo.setResult(list);
        //3.封装ResponseVo
        return responseVo;
    }

    @Override
    public ResponseVo<Business> findBusinessById(Integer id) {
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        IBusinessMapper mapper =sqlSession.getMapper(IBusinessMapper.class);
        //2.调用mapper层相应方法
        Business business=mapper.findBusinessById(id);
        // 3.封装ResponseVo
        ResponseVo<Business> responseVo=new ResponseVo<>();

        responseVo.setFlag(true);
        responseVo.setMessage("查询成功");
        responseVo.setResult(business);

        return responseVo;
    }

    @Override
    public ResponseVo<List<Business>> getTop3BusinessList() {
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        IBusinessMapper mapper =sqlSession.getMapper(IBusinessMapper.class);
        List<Business> list=mapper.getTop3BusinessList();
        //2.调用mapper层相应方法
        ResponseVo<List<Business>> responseVo=new ResponseVo<>();

        responseVo.setFlag(true);
        responseVo.setMessage("查询成功");
        responseVo.setResult(list);

        return responseVo;
    }

    @Override
    public ResponseVo<List<Business>> findBusinessByOrderTypeId(Integer id) {
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        IBusinessMapper mapper =sqlSession.getMapper(IBusinessMapper.class);
        List<Business> list=mapper.findBusinessByOrderTypeId(id);
        //2.调用mapper层相应方法
        ResponseVo<List<Business>> responseVo=new ResponseVo<>();

        responseVo.setFlag(true);
        responseVo.setMessage("查询成功");
        responseVo.setResult(list);

        return responseVo;
    }
}
